/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.manage.service;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.account.core.repository.entity.AccountTransLogEntity;
import info.peigen.hotpot.business.account.manage.convertor.AccountTransLogManageConvertor;
import info.peigen.hotpot.business.account.manage.form.AccountTransLogManageCreateForm;
import info.peigen.hotpot.business.account.manage.form.AccountTransLogManageEditForm;
import info.peigen.hotpot.business.account.manage.form.AccountTransLogManageSearchForm;
import info.peigen.hotpot.business.account.manage.info.AccountTransLogManageInfo;
import info.peigen.hotpot.business.account.manage.repository.service.AccountTransLogManageRepository;
import info.peigen.hotpot.common.core.result.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.core.query.Query;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(AccountTransLogManageService)</b>
 * 管理后台 "账户交易流水记录" 服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-08-30
 */
@SuppressWarnings("unused")
@Component
public class AccountTransLogManageService {
    @Inject
    AccountTransLogManageRepository accountTransLogManageRepository;

    public PageResult<AccountTransLogManageInfo> page(AccountTransLogManageSearchForm form) {
        LambdaQuery<AccountTransLogEntity> lambdaQuery = accountTransLogManageRepository.getMapper().createLambdaQuery()
                .andLike(AccountTransLogEntity::getTransLogId, Query.filterLikeEmpty(form.getTransLogId(), false, true))
                .andLike(AccountTransLogEntity::getTradeId, Query.filterLikeEmpty(form.getTradeId(), false, true))
                .andLike(AccountTransLogEntity::getTransCode, Query.filterLikeEmpty(form.getTransCode(), false, true))
                .andLike(AccountTransLogEntity::getDebitAccountId, Query.filterLikeEmpty(form.getDebitAccountId(), false, true))
                .andLike(AccountTransLogEntity::getCreditAccountId, Query.filterLikeEmpty(form.getCreditAccountId(), false, true))
                .andLike(AccountTransLogEntity::getTransTime, Query.filterLikeEmpty(form.getTransTime(), false, true))
                .andLike(AccountTransLogEntity::getSettleTime, Query.filterLikeEmpty(form.getSettleTime(), false, true))
                .andLike(AccountTransLogEntity::getPartnerId, Query.filterLikeEmpty(form.getPartnerId(), false, true));

        return accountTransLogManageRepository.page(form.getPageNum(), form.getPageSize(), lambdaQuery, AccountTransLogManageConvertor::convertToInfo);
    }

    public void create(AccountTransLogManageCreateForm form) {
        AccountTransLogEntity entity = BeanUtil.copyProperties(form, AccountTransLogEntity.class);
        accountTransLogManageRepository.save(entity);
    }

    public void edit(AccountTransLogManageEditForm form) {
        AccountTransLogEntity entity = BeanUtil.copyProperties(form, AccountTransLogEntity.class);
        accountTransLogManageRepository.saveOrUpdate(entity);
    }

    public void remove(Integer id) {
        accountTransLogManageRepository.delete(id);
    }
}